<template>
  <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
    <el-form-item label="申请人" prop="accountHolder">
      <el-input
        v-model="queryParams.accountHolder"
        placeholder="请输入申请人姓名"
        clearable
        style="width: 240px"
        @keyup.enter="handleQuery"
      />
    </el-form-item>
    <el-form-item label="公寓名称" prop="apartmentName">
      <el-input
        v-model="queryParams.apartmentName"
        placeholder="请输入公寓名称"
        clearable
        style="width: 240px"
        @keyup.enter="handleQuery"
      />
    </el-form-item>
    <el-form-item label="审核状态" prop="auditStatus">
      <el-select v-model="queryParams.auditStatus" placeholder="审核状态" clearable>
        <el-option
          v-for="dict in withdraw_audit_status"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="支付状态" prop="paymentStatus">
      <el-select v-model="queryParams.paymentStatus" placeholder="支付状态" clearable>
        <el-option
          v-for="dict in withdraw_payment_status"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="申请时间" prop="dateRange">
      <el-date-picker
        v-model="dateRange"
        style="width: 240px"
        value-format="YYYY-MM-DD"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
      <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
const { proxy } = getCurrentInstance()
const { withdraw_audit_status, withdraw_payment_status } = proxy.useDict('withdraw_audit_status', 'withdraw_payment_status')

const props = defineProps({
  showSearch: {
    type: Boolean,
    default: true
  },
  queryParams: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['query', 'reset'])

const queryRef = ref()
const dateRange = ref([])

const handleQuery = () => {
  // 处理日期范围
  if (dateRange.value && dateRange.value.length === 2) {
    props.queryParams.startTime = dateRange.value[0]
    props.queryParams.endTime = dateRange.value[1]
  } else {
    props.queryParams.startTime = undefined
    props.queryParams.endTime = undefined
  }
  
  props.queryParams.pageNum = 1
  emit('query')
}

const resetQuery = () => {
  dateRange.value = []
  proxy.resetForm("queryRef")
  emit('reset')
}
</script> 